package demo2;
public class Test {

    public static void main(String[] args) {
        Animal animal = new Dog("旺财",6);
        if(animal instanceof Dog){
            Dog dog = (Dog) animal;
            dog.bark();
        }else {
            System.out.println("animal not instanceof Dog");
        }

        if(animal instanceof  Cat){
            Cat cat = (Cat) animal;
            cat.mew();
        }else {
            System.out.println("animal not instanceof Cat");
        }

    }

    public static void eatting(Animal animal){
        animal.eat();
    }

    public static void main5(String[] args) {
        Dog dog = new Dog("旺财", 2);
        eatting(dog);

        Cat cat = new Cat("咪咪", 1);
        eatting(cat);
    }

    public static void main4(String[] args) {
        Animal animal = new Dog("旺财", 2);
        /*animal.color;
        animal.bark();*/
        animal.eat();
    }

    public static Animal func2(){
        return new Dog("旺财", 3);
    }

    public static void func(Animal animal){

    }

    public static void main3(String[] args) {
        Dog dog = new Dog("旺旺",3);
        func(dog);

        System.out.println("================");

        Cat cat = new Cat("咪咪", 2);
        func(cat);

        Animal animal = func2();
    }

    public static void main2(String[] args) {
        /*Dog dog = new Dog("旺财", 1);
        Animal animal = dog;*/

        Animal animal = new Dog("旺财", 1);
        Animal animal1 = new Cat("喵喵", 2);
    }

    public static void main1(String[] args) {
        Dog dog = new Dog("旺旺",3);
        dog.bark();
        dog.eat();

        System.out.println("=====================");

        Cat cat = new Cat("咪咪", 2);
        cat.mew();
        cat.eat();

    }
}
